<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-tickets"></i>投票列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button> -->
                <el-input v-model="title" placeholder="投票标题" class="handle-input mr10"></el-input>
                <el-date-picker v-model="startTime" type="datetime" class="handle-select" placeholder="开始日期" ></el-date-picker>
                <el-date-picker v-model="endTime" type="datetime"  class="handle-select" placeholder="结束日期"></el-date-picker>
                <el-select v-model="type" placeholder="类型" class="handle-select mr10">
                     <el-option label="请选择" value=""></el-option>
                    <el-option key="0" label="单选" value="0"></el-option>
                    <el-option key="1" label="多选" value="1"></el-option>
                </el-select>
                <transition name="fade">
                 <el-select v-model="open" placeholder="状态" class="handle-select mr10" v-if="show">
                     <el-option label="请选择" value=""></el-option>
                    <el-option key="0" label="投票中" value="0"></el-option>
                    <el-option key="1" label="已结束" value="1"></el-option>
                </el-select>
                </transition>
                <el-button type="primary" icon="search" @click="search">搜索</el-button>
                <el-button type="primary" icon="search" @click="show = !show">but</el-button>
            </div>
            <el-table :data="voteData" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
                <!-- <el-table-column type="selection" width="40"></el-table-column> -->
                <el-table-column prop="id" label="编号" sortable align="center">
                </el-table-column>
                <el-table-column prop="nickName" label="发起人" align="center" :formatter="nickName">
                </el-table-column>
                <el-table-column prop="title" label="投票标题" align="center">
                </el-table-column>
                <el-table-column prop="type" label="类型" align="center" :formatter="typeStatus">
                </el-table-column>
                <el-table-column prop="startTime" label="创建时间" align="center">
                </el-table-column>
                <el-table-column prop="endTime" label="结束时间" align="center">
                </el-table-column>
                <el-table-column prop="open" label="状态" align="center" :formatter="openStatus">
                </el-table-column>
                <el-table-column prop="joinNum" label="参与人数" align="center" >
                </el-table-column>
                <el-table-column label="操作" width="180" fixed="right" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="see(scope.$index, scope.row)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage4"
                    :page-sizes="[10, 15, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { Message } from 'element-ui';
import { getVoteData } from '../../components/api/vote.js';
    export default {
        // inject:['reload'],
        name: 'basetable',
        data() {
            return {
                show:true,
                tableData: [],
                multipleSelection: [],
                pageSize:10,
                pageNum:1,
                form: {
                    name: '',
                    date: '',
                    address: ''
                },
                voteData:[],
                startTime:'',
                endTime:'',
                title:'',
                type:'',
                open:'',
                idx: -1,
                currentPage4:1,
                total:0,
                detailsData:{}
            }
        },
        created() {
            this.getData();
            // this.reload();
        },
        computed: {
      
        },
        methods: {

            //选择列表数据条数
            handleSizeChange(val) {
                console.log('每页'+val+'条数');
                this.pageSize = val;
                this.getData();
            },
            //选择列表数据分页
            handleCurrentChange(val) {
                console.log('当前页'+val);
                this.pageNum = val;
                this.getData();
            },

            getData() {
                let router = this.$router;
                let params = {
                    endTime:this.endTime,
                    title:this.title,
                    type:this.type,
                    open:this.open,
                    startTime:this.startTime,
                    pageNum:this.pageNum,
                    pageSize:this.pageSize
                };

                //获取列表数据
               getVoteData(params).then((res)=>{
                   if(res.status == 200){
                       console.log(res);
                       this.voteData = res.data.voteTopicList;
                       this.total = res.data.total
                   }
                   console.log(res);
               }).catch((err)=>{
                   console.log(err);
               });
            },

            //列表搜索功能
            search() {
                this.getData();
            },
            nickName(row,column){

                let Base64 = require('js-base64').Base64;
                return Base64.decode(row.nickName);

            },
            openStatus(row,column){
                if(row.open == 1){
                    return '已结束'
                }else{
                    return '投票中'
                }
            },
            typeStatus(row,column){
                if(row.type == 1){
                    return '多选'
                }else{
                    return '单选'
                }
            },

            //查看活动详情
            see(index, row) {     
                console.log(row.id);          
                this.$router.push({name:'voteDetails',params:{id:row.id}});
                
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }

</script>

<style scoped>
    .add-user{
        float:right;
    }
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 190px;
    }

    .handle-input {
        width: 190px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .handle-botton{
        margin: 0 0 20px 80px;
    }
    .vote{
        font-size: 17px;
        color: black;
        padding:0 200px;
    }
    .leaving>p{
        height:40px;
        line-height: 40px;
    }

    .fade-enter-active {
        transition: all .5s ease-out;
    }
     .fade-leave-active{
         transition:all 1s ;
     }
    .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
        transform: translateX(20px);
        opacity: 0;
    }
</style>
